<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios.js"></script>
    <script src="../plugins/echarts/echarts.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>统计分析<small>会员数量</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>会员数量</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="block">
                <font size="6px"><b>选择查询日期 :</b></font>&nbsp;&nbsp;
                <el-date-picker
                        v-model="value"
                        type="monthrange"
                        align="right"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始月份"
                        end-placeholder="结束月份"
                        value-format="yyyy-MM"
                        :picker-options="pickerOptions">
                </el-date-picker>&nbsp;&nbsp;&nbsp;&nbsp;
                <el-button @click="findByDate()" :model="value" icon="el-icon-search" circle></el-button>
            </div>
            <hr size="2px" color="#7E7788"/>
            <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
            <div id="chart1" style="height:600px;"></div>
        </div>
    </div>
</div>
</body>

<script type="text/javascript">
    /*返回数据格式{flag:xxx,message:xxxx,
    data{
        text:'近一年会员注册数量',
        memberNumberByDate{
            dataMonth:['','',]
            dataCount:[x,x,x,]
        }

    }*/
    new Vue({
        el:"#app",
        data: {
            months:[],
            memberCount:[],
            value: [],
            text:['近一年会员注册数量'],
            pickerOptions: {
                shortcuts: [{
                    text: '本月',
                    onClick(picker) {
                        picker.$emit('pick', [new Date(), new Date()]);
                    }
                }, {
                    text: '最近六个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setMonth(start.getMonth() - 6);
                        picker.$emit('pick', [start, end]);
                    }
                },{
                    text: '今年至今',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date(new Date().getFullYear(), 0);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
        },
        methods:{
            findByDate(){
                /*alert(this.value);
                var param = JSON.stringify(this.value);*/
                axios.post("/memberReport/findMemberNumberByDate.do",this.value).then((res) => {
                    if (res.data.flag){
// 基于准备好的dom，初始化echarts实例
                    var myChart1 = echarts.init(document.getElementById('chart1'));
                    myChart1.setOption(
                        {
                            title: {
                                text: res.data.data.text,
                                left: 'center',
                            },
                            tooltip: {},
                            /*legend: {
                                data: ['会员数量']
                            },*/
                            xAxis: {
                                data: res.data.data.months//月数
                            },
                            yAxis: {
                                type: 'value'
                            },
                            series: [{
                                name: '会员数量',
                                type: 'line',
                                data: res.data.data.memberCount//数量
                            }]
                        });
                    // 使用刚指定的配置项和数据显示图表。
                    myChart1.setOption(option);
                }else{
                    this.$message({
                        type:"success",
                        message:res.data.message
                    });
                }
            });
            }
        },
        /*
        * 这儿体现出来了created和mounted的区别,created是在页面加载时,mounted是在页面加载完毕之后
        * */
        mounted(){
            axios.get("/report/getMemberReport.do").then((res) => {
                // 基于准备好的dom，初始化echarts实例
                var myChart1 = echarts.init(document.getElementById('chart1'));
            myChart1.setOption(
                {
                    title: {
                        text: this.text,
                        left: 'center',
                    },
                    tooltip: {},
                    /*legend: {
                        data: ['会员数量']
                    },*/
                    xAxis: {
                        data: res.data.data.months//月数
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '会员数量',
                        type: 'line',
                        data: res.data.data.memberCount//数量
                    }]
                });
            // 使用刚指定的配置项和数据显示图表。
            myChart1.setOption(option);
        });
        }
    });
</script>
</html>
